package com.lyn.chapter2.demo1;

import com.lyn.kit.Tools;

public class WorkerThread extends Thread{
	private final int requestCount;
	
	public WorkerThread(int id, int requestCount) {
		super("Worker-" + id);
		this.requestCount = requestCount;
	}
	
	@Override
	public void run() {
		int i= requestCount;
		String requestID;
		RequestIDGenerator gen = RequestIDGenerator.getInstance();
		while(i-->0) {
			requestID = gen.nextID();
			processRequest(requestID);
		}
	}
	
	private void processRequest(String requestID) {
		Tools.randomPause(50);
		System.out.printf("%s got requestID: %s %n", 
				Thread.currentThread().getName(), requestID);
	}
	
}
